package dao;

import java.io.InputStream;
import java.util.Properties;
import java.sql.*;

public class Base {
    private  static Properties properties=new Properties();
     static {
         InputStream in= Base.class.getClassLoader().getResourceAsStream("pd.properties");
         try
         {
             properties.load(in);
             Class.forName(properties.getProperty("pd_driver"));

         }catch (Exception e){
             e.printStackTrace();
         }
     }

     public static Connection getConnection(){
         Connection conn=null;
         try{
             String pdUrl= properties.getProperty("pd_url");
             String pdName = properties.getProperty("pd_name");
             String pdPassword= properties.getProperty("pd_password");
             conn=DriverManager.getConnection(pdUrl,pdName,pdPassword);
         }catch (SQLException e){
             e.printStackTrace();
         }
         return conn;
     }

     public static void close(Connection conn,PreparedStatement pst,ResultSet set){
          try{
              if(set != null){
                  set.close();
              }

              if(pst != null){
                  pst.close();
              }

              if(conn != null){
                  conn.close();
              }
          }catch (Exception e){
              e.printStackTrace();
          }
     }
}
